package cn.bgs.util;


import com.alibaba.fastjson.JSON;
import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTCreator;
import com.auth0.jwt.algorithms.Algorithm;
import lombok.extern.slf4j.Slf4j;

import java.util.Calendar;

@Slf4j
public class JwtUtils {
    private static final String SECRET = "roadjava.com";
    /**
     * 生成token
     * */
    public static <T>String getToken(T t){
        Calendar instance= Calendar.getInstance();
        instance.add(Calendar.MONTH,1);
        JWTCreator.Builder builder =JWT.create()
                .withClaim(t.getClass().getSimpleName(), JSON.toJSONString(t));
       String token= builder.withExpiresAt(instance.getTime()).sign(Algorithm.HMAC256(SECRET));
       return  token;
    }
}
